<template>
	<view class="pages custom-inspection-list">
		<!-- 头部header -->
		<view class="header">
			<uni-nav-bar :statusBar="true" :showHistory="!controlBol" leftIcon="arrowleft" fixed="true" :title="headTitle" @checkHistory="checkHistory" @clickLeft="clickLeft"></uni-nav-bar>
		</view>
		<view class="p-content">
			<view class="inspection-list-wrap">
				<inspection-list type="editable" :alreadyNum="inspectionItem.alreadyNum" :totalNum="inspectionItem.totalNum"
				 :unchecked="tempInspectionItem.unchecked" :checked="tempInspectionItem.checked" @refresh="refresh" :controlBol="controlBol" >
				</inspection-list>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inspectionItem: {}, // 日巡查清单各项目列表查询
				tempInspectionItem: {}, // 临时数据 日巡查清单各项目列表查询
				inspectMenuId: '',
				controlBol:true
			}
		},
		onLoad(value) {
			if (value.bol === 'false') {
				this.controlBol = false
				console.log("4")
			} else {
				this.controlBol = true
				console.log("5")
			}
			
			this.inspectMenuId = value.inspectMenuId
			
			this.initPage()
		},
		computed: {
			headTitle() {
				let date = new Date()
				let year = date.getFullYear()
				let month = date.getMonth() + 1
				let day = date.getDate()
				return `日巡查清单${year}-${month > 9 ? month : '0' + month}-${day}`
			}
		},
		methods: {
			/**
			 * @description: 打开历史记录页面
			 * @author: LinW (evan_origin@163.com)
			 * @createDate: 2019-11-20 11:25
			 */
			checkHistory(){
				uni.navigateTo({
					url:'./inspectionHistory/inspectionHistory'
				})
			},
			/**
			 * @description: 刷新数据请求
			 * @author: LinW (evan_origin@163.com)
			 * @createDate: 2019-11-20 11:25
			 */
			refresh() {
				// this.tempInspectionItem.unchecked.forEach(item=>{
				// 	item.dayInspectFlag = true
				// })
				this.getInspectionList()
			},
			/**
			 * @description: 页面初始化
			 * @author: LinW (evan_origin@163.com)
			 * @createDate: 2019-11-15 10:13
			 * @param: mod
			 * @return:
			 */
			initPage() {
				// Indicator.open({
				// 	text: '加载中...',
				// 	spinnerType: 'fading-circle'
				// })
				this.getInspectionList()
			},
			/**
			 * @description: 获取 日巡查清单各项目的列表数据
			 * @author: LinW (evan_origin@163.com)
			 * @createDate: 2019-11-14 14:52
			 * @param: mod
			 * @return:
			 */
			getInspectionList() {
				this.$request.ygstInspectMenuItemListGet(this.inspectMenuId).then(res => {
					// Indicator.close()
					if (!this.$utils.isEmptyObject(res) && res.list.length > 0) {
						this.inspectionItem = res
						this.tempInspectionItem = JSON.parse(JSON.stringify(this.inspectionItem))
						this.orderSortData()
						
					}
				}).catch(e => {
					// Indicator.close()
					console.log(e)
				})
			},
			/**
			 * @description: 处理后端返回数据
			 * @author: LinW (evan_origin@163.com)
			 * @createDate: 2019-11-14 15:06
			 */
			orderSortData() {
				// add order to inspectContent
				this.tempInspectionItem.list.forEach((item, index) => {
					item.order = (index + 1)
				})
				console.log(this.tempInspectionItem.list)
				// classify (unchecked and checked)
				let unchecked = this.tempInspectionItem.list.filter(item => item.dayInspectFlag === 0)
				let checked = this.tempInspectionItem.list.filter(item => item.dayInspectFlag === 1)
				this.tempInspectionItem.unchecked = unchecked
				this.tempInspectionItem.unchecked.forEach(item => item.dayInspectFlag = false)
				this.tempInspectionItem.checked = checked
				this.tempInspectionItem.checked.forEach(item => item.dayInspectFlag = true)
				this.options = this.tempInspectionItem.unchecked
				console.log(this.tempInspectionItem.unchecked,'=-=-=-=-')
			},
			/**
			 * @description: 返回上一页
			 * @author: LinW (xuebingchuan_20@163.com)
			 * @createDate: 2020-10-10 10:40
			 */
			clickLeft() {
				uni.navigateBack()
			},
		}
	}
</script>

<style>

</style>
